import { _decorator, Component, EventHandler, find, Label, Node, RichText } from 'cc';
import { UnitPlanet } from '../../Entity/UnitPlanet';
import { Global } from '../../Util/Global';
import GameEventMgr, { GameEvent } from '../../Model/GameEventMgr';
const { ccclass, property } = _decorator;

@ccclass('StartGameViewUI')
export class StartGameViewUI extends Component {
    @property(UnitPlanet)
    startPlayer: UnitPlanet = null;

    private _notice: RichText = null;
    get notice() {
        if (this._notice == null) {
            this._notice = find('GameNotice/message', this.node).getComponent(RichText);
        }
        return this._notice;
    }

    protected start(): void {
        console.log(this.startPlayer);
        Global.gameManager.playerCtrl.playerUnit = this.startPlayer;//提前绑定这个对象，让摄像机跟随移动
        Global.gameManager.mapCtrl.player = this.startPlayer;
        this.notice.string = '';
    }

    onClickGameStart(event: EventHandler, customEventData: string) {
        if (this.startPlayer && this.startPlayer.node) {

            Global.gameManager.GameStartByUnit(this.startPlayer);
        }
        else {
            Global.gameManager.GameStart();
        }
        this.node.active = false;
    }
}


